<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="上级标准" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="achievementStandardId">
<!--              <a-input v-model="model.achievementStandardId" placeholder="请输入所属上级标准id"  ></a-input>-->
              <j-dict-select-tag type="list" v-model="model.achievementStandardId" disabled
                                 dictCode="ach_achievement_standard aas,aas.achievement_standard_name,aas.id,aas.del_flag = 0 and aas.iz_open = 1 order by aas.achievement_standard_order" placeholder="请输入所属上级标准id" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="科目" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="subjectId">
<!--              <a-input v-model="model.subjectId" placeholder="请输入科目id"  ></a-input>-->
              <j-dict-select-tag type="list" v-model="model.subjectId" disabled
                                 dictCode="cou_subject cs,cs.subject_name,cs.id,cs.del_flag = 0 and cs.subject_iz_open = 1 order by cs.subject_order" placeholder="请输入标准科目" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="项目Code" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="exaPapProItemCode">
              <a-input v-model="model.exaPapProItemCode" placeholder="请输入考试项目code(来源于项目模板或项目分配表）"  disabled></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="分项编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="standItemCode">
              <a-input v-model="model.standItemCode" placeholder="请输入标准分项编码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="分项目名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="standItemName">
              <a-input v-model="model.standItemName" placeholder="请输入标准分项目名称(不及格、及格、良好、优秀等）"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="别名(简称)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="standItemAliasname">
              <a-input v-model="model.standItemAliasname" placeholder="请输入标准分项目别名简称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="项目序号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="standItemOrder">
              <a-input-number v-model="model.standItemOrder" placeholder="请输入项目序号" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>

        <a-row>
          <a-col :span="12">
            <a-form-model-item label="分数最低分(含)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="standItemLowestScore">
              <a-input-number v-model="model.standItemLowestScore" placeholder="请输入分数最低分(含)" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="分数最高分(不含)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="standItemHighestScore">
              <a-input-number v-model="model.standItemHighestScore" placeholder="请输入分数最高分(不含)" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="分数最低百分比(含)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="standItemLowestRate">
              <a-input-number v-model="model.standItemLowestRate" placeholder="请输入分数最低分率百分比(含)" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="分数最高百分比(不含)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="standItemHighestRate">
              <a-input-number v-model="model.standItemHighestRate" placeholder="请输入分数最高分率百分比(不含)" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="评分实际得分" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="standItemActualScore">
              <a-input-number v-model="model.standItemActualScore" placeholder="请输入标准分项评分实际得分" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>

        <a-row>
          <a-col :span="12">
            <a-form-model-item label="特殊限制" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="standItSpecialRestrictions">
              <a-input-number v-model="model.standItSpecialRestrictions" placeholder="请输入特殊限制（0无限制，1性别，2年级 3年龄，4预留）" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="限制数最小值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sitemSpecRestMinvalue">
              <a-input-number v-model="model.sitemSpecRestMinvalue" placeholder="请输入特殊限制数最小值（含即大于等于或等于）" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="限制数最大值" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sitemSpecRestMaxvalue">
              <a-input-number v-model="model.sitemSpecRestMaxvalue" placeholder="请输入特殊限制数最大值（不含或小于）" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="上级项目" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="standItemFatherId">
              <a-input v-model="model.standItemFatherId" placeholder="请输入上级项目id"  ></a-input>
            </a-form-model-item>
          </a-col>
<!--          <a-col :span="12">-->
<!--            <a-form-model-item label="是否启用" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="izOpen">-->
<!--              <a-input-number v-model="model.izOpen" placeholder="请输入是否启用(1是启用，0否停用)" style="width: 100%" />-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
          <!--          <a-col :span="24">-->
          <!--            <a-form-model-item label="部门编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sysOrgCode">-->
          <!--              <a-input v-model="model.sysOrgCode" placeholder="请输入所属部门编码"  ></a-input>-->
          <!--            </a-form-model-item>-->
          <!--          </a-col>-->
          <!--          <a-col :span="24">-->
          <!--            <a-form-model-item label="学校id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenantId">-->
          <!--              <a-input v-model="model.tenantId" placeholder="请输入学校id"  ></a-input>-->
          <!--            </a-form-model-item>-->
          <!--          </a-col>-->
<!--          <a-col :span="12">-->
<!--            <a-form-model-item label="是否删除" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="delFlag">-->
<!--              <a-input-number v-model="model.delFlag" placeholder="请输入0表示未删除,1表示删除" style="width: 100%" />-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
          <!--          <a-col :span="24">-->
          <!--            <a-form-model-item label="创建人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="createBy">-->
          <!--              <a-input v-model="model.createBy" placeholder="请输入创建人"  ></a-input>-->
          <!--            </a-form-model-item>-->
          <!--          </a-col>-->
          <!--          <a-col :span="24">-->
          <!--            <a-form-model-item label="创建时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="createTime">-->
          <!--              <j-date placeholder="请选择创建时间" v-model="model.createTime"  style="width: 100%" />-->
          <!--            </a-form-model-item>-->
          <!--          </a-col>-->
          <!--          <a-col :span="24">-->
          <!--            <a-form-model-item label="修改人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="updateBy">-->
          <!--              <a-input v-model="model.updateBy" placeholder="请输入修改人"  ></a-input>-->
          <!--            </a-form-model-item>-->
          <!--          </a-col>-->
          <!--          <a-col :span="24">-->
          <!--            <a-form-model-item label="修改时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="updateTime">-->
          <!--              <j-date placeholder="请选择修改时间" v-model="model.updateTime"  style="width: 100%" />-->
          <!--            </a-form-model-item>-->
          <!--          </a-col>-->
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

import { httpAction, getAction } from '@/api/manage'
import { validateDuplicateValue } from '@/utils/util'

export default {
  name: 'FormCopyAddStandardItemForm',
  components: {
  },
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    }
  },
  data () {
    return {
      model:{
        statusKey: null,
      },
      labelCol: {
        xs: { span: 24 },
        sm: { span: 8 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 14 },
      },
      confirmLoading: false,
      validatorRules: {
      },
      url: {
        add: "/achachievestandarditem/achAchieveStandardItem/add",
        edit: "/achachievestandarditem/achAchieveStandardItem/edit",
        queryById: "/achachievestandarditem/achAchieveStandardItem/queryById"
      },

    }
  },
  computed: {
    formDisabled(){
      return this.disabled
    },
  },
  created () {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model));
  },
  methods: {
    add (record) {
      record.id = null,//复制式新增式清空id
      this.modelDefault = Object.assign({}, record);
      this.edit(this.modelDefault);
    },
    edit (record) {
      //编辑
      this.model = Object.assign({}, record);
      this.copyAddVisible = true;
    },
    submitForm () {
      const that = this;
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true;
          let httpurl = '';
          let method = '';
          //复制式新增(statusKey === 1) ,编辑(statusKey === 2)
          if(this.model.statusKey === 1){
            httpurl+=this.url.add;
            method = 'post';
          }else{
            httpurl+=this.url.edit;
            method = 'put';
          }
          httpAction(httpurl,this.model,method).then((res)=>{
            if(res.success){
              that.$message.success(res.message);
              that.$emit('ok');
            }else{
              that.$message.warning(res.message);
            }
          }).finally(() => {
            that.confirmLoading = false;
          })
        }

      })
    },


  }
}
</script>